package nc.impl.hrpbm.budget;

import nc.bs.dao.BaseDAO;
import nc.bs.hrpbm.budget.IBudgetKeywordService;
import nc.jdbc.framework.processor.MapListProcessor;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * 中间表budget_keyword_xmheart
 * */
public class BudgetKeywordImpl implements IBudgetKeywordService {

    private BaseDAO dao;
    private BaseDAO  getDAO() {
        if (dao == null) {
            dao = new BaseDAO();
        }
        return dao;
    }

    private final String TABLE_NAME = "budget_keyword_xmheart";
    @Override
    public Map<String, String> queryKeywordList(Set<String> codes) throws Exception {
        Map<String, String> dict = new HashMap<String, String>();
        if (codes != null || codes.size() > 0) {
            String sql = " select billcode,keyword from " + TABLE_NAME + " where billcode in ('" + String.join("','", codes) + "') ";
            List<Map<String, String>> res = (List<Map<String, String>>) getDAO().executeQuery(sql, new MapListProcessor());
            if (res != null && res.size() > 0) {
                res.forEach(map -> {
                    dict.put(map.get("billcode"), map.get("keyword"));
                });
            }
        }
        return dict;
    }
}
